<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>购物车页面</title>
<link href="../static/css/amazeui.css" rel="stylesheet" type="text/css" />
<link href="../static/css/demo.css" rel="stylesheet" type="text/css" />
<link href="../static/css/cartstyle.css" rel="stylesheet" type="text/css" />
<link href="../static/css/optstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../static/js/myinit.js"></script>
<script type="text/javascript" src="../static/js/cook_shop_cart.js"></script>
</head>

<body>

	<!--顶部导航条 -->
	<div class="am-container header">
		<ul class="message-l">
			<div class="topMessage">
				<div class="menu-hd">
					<a href="#" target="_top" class="h">亲，请登录</a> <a href="#"
						target="_top">免费注册</a>
				</div>
			</div>
		</ul>
		<ul class="message-r">
			<div class="topMessage home">
				<div class="menu-hd">
					<a href="#" target="_top" class="h">商城首页</a>
				</div>
			</div>
			<div class="topMessage my-shangcheng">
				<div class="menu-hd MyShangcheng">
					<a href="#" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a>
				</div>
			</div>
			<div class="topMessage mini-cart">
				<div class="menu-hd">
					<a id="mc-menu-hd" href="#" target="_top"><i
						class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong
						id="J_MiniCartNum" class="h">0</strong></a>
				</div>
			</div>
			<div class="topMessage favorite">
				<div class="menu-hd">
					<a href="#" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a>
				</div>
			</div>
		</ul>
	</div>

	<!--悬浮搜索框-->

	<div class="nav white">
		<div class="logo">
			<img src="../static/img/logo.png" />
		</div>
		<div class="logoBig">
			<li><img src="../static/img/logobig.png" /></li>
		</div>
		<div class="search-bar pr">
			<a name="index_none_header_sysc" href="#"></a>
			<form>
				<input id="searchInput" name="index_none_header_sysc" type="text"
					placeholder="搜索" autocomplete="off"> <input
					id="ai-topsearch" class="submit am-btn" value="搜索" index="1"
					type="submit">
			</form>
		</div>
	</div>
	<div class="clear"></div>

	<!--购物车 -->
	<div class="concent">
		<div id="cartTable">
			<div class="cart-table-th">
				<div class="wp">
					<div class="th th-chk">
						<div id="J_SelectAll1" class="select-all J_SelectAll"></div>
					</div>
					<div class="th th-item">
						<div class="td-inner">商品信息</div>
					</div>
					<div class="th th-price">
						<div class="td-inner">单价</div>
					</div>
					<div class="th th-amount">
						<div class="td-inner">数量</div>
					</div>
					<div class="th th-sum">
						<div class="td-inner">金额</div>
					</div>
					<div class="th th-op">
						<div class="td-inner">操作</div>
					</div>
				</div>
			</div>
			<div class="clear"></div>
			<tr class="item-list">
				<div class="bundle  bundle-last ">

					<div class="clear"></div>
					<div class="bundle-main">

						<div  id="shopcartitemlist">
						</div>
						<!--  
						<div class="bundle-hd">
							<div class="bd-promos">
								<div class="bd-has-promo">
									已享优惠:<span class="bd-has-promo-content">省￥19.50</span>&nbsp;&nbsp;
								</div>
								<div class="act-promo">
									<a href="#" target="_blank">第二支半价，第三支免费<span class="gt">&gt;&gt;</span></a>
								</div>
								<span class="list-change theme-login">编辑</span>
							</div>
						</div>
						-->

					</div>
				</div>
			</tr>
			<div class="clear"></div>

		</div>
		<div class="clear"></div>
		<div class="float-bar-wrapper">
			<div id="J_SelectAll2" class="select-all J_SelectAll">
				<div class="cart-checkbox">
					<input class="check-all check" id="J_SelectAllCbx2"
						name="select-all" value="true" style="margin-top:0px" type="checkbox"> <label
						for="J_SelectAllCbx2"></label>
				</div>
				<span>全选</span>
			</div>
			<div class="operations">
				<a href="#" hidefocus="true" class="deleteAll">删除</a> <a href="#"
					hidefocus="true" class="J_BatchFav" style="display:none">移入收藏夹</a>
			</div>
			<div class="float-bar-right">
				<div class="amount-sum">
					<span class="txt">已选商品</span> <em id="J_SelectedItemsCount">0</em><span
						class="txt">件</span>
					<div class="arrow-box">
						<span class="selected-items-arrow"></span> <span class="arrow"></span>
					</div>
				</div>
				<div class="price-sum">
					<span class="txt">合计:</span> <strong class="price">¥<em
						id="J_Total">0.00</em></strong>
				</div>
				<div class="btn-area">
					<a id="J_Go" class="submit-btn submit-btn-disabled"
						aria-label="请注意如果没有选择宝贝，将无法结算"> <span>结&nbsp;算</span></a>
				</div>
			</div>
		</div>
		<div class="footer ">
			<div class="footer-hd">
				<p>
					<img src="../static/img/duo.png" style="width: 25px" />品类齐全<b>|</b><img
						src="../static/img/kuai.png" style="width: 25px" />多仓直发<b>|</b><img
						src="../static/img/hao.png" style="width: 25px" />正品行货<b>|</b><img
						src="../static/img/sheng.png" style="width: 25px" />天天低价
				</p>
			</div>
			<div class="footer-bd "></div>
		</div>
	</div>

	<!--操作页面-->
<!--
	<div class="theme-popover-mask"></div>
	<div class="theme-popover">
		<div class="theme-span"></div>
		<div class="theme-poptit h-title">
			<a href="javascript:;" title="关闭" class="close">×</a>
		</div>
		<div class="theme-popbod dform">
			<form class="theme-signin" name="loginform" action="" method="post">
				<div class="theme-signin-left">
					<li class="theme-options">
						<div class="cart-title">颜色：</div>
						<ul>
							<li class="sku-line selected">12#川南玛瑙<i></i></li>
							<li class="sku-line">10#蜜橘色+17#樱花粉<i></i></li>
						</ul>
					</li>
					<li class="theme-options">
						<div class="cart-title">包装：</div>
						<ul>
							<li class="sku-line selected">包装：裸装<i></i></li>
							<li class="sku-line">两支手袋装（送彩带）<i></i></li>
						</ul>
					</li>
					<div class="theme-options">
						<div class="cart-title number">数量</div>
						<dd>
							<input class="min am-btn am-btn-default" name="" type="button"
								value="-" /> <input class="text_box" name="" type="text"
								value="1" style="width: 30px;" /> <input
								class="add am-btn am-btn-default" name="" type="button"
								value="+" /> <span class="tb-hidden">库存<span
								class="stock">1000</span>件
							</span>
						</dd>
					</div>
					<div class="clear"></div>
					<div class="btn-op">
						<div class="btn am-btn am-btn-warning">确认</div>
						<div class="btn close am-btn am-btn-warning">取消</div>
					</div>
				</div>
				<div class="theme-signin-right">
					<div class="img-info">
						<img src="../static/img/kouhong.jpg_80x80.jpg" />
					</div>
					<div class="text-info">
						<span class="J_Price price-now">¥39.00</span> <span id="Stock"
							class="tb-hidden">库存<span class="stock">1000</span>件
						</span>
					</div>
				</div>
			</form>
		</div>
	</div>
	-->
	<!--引导 -->
	<div class="navCir">
		<li><a href="home.html"><i class="am-icon-home "></i>首页</a></li>
		<li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
		<li class="active"><a href="shopcart.html"><i
				class="am-icon-shopping-basket"></i>购物车</a></li>
		<li><a href="person/index.html"><i class="am-icon-user"></i>我的</a></li>
	</div>
	<script type="text/javascript">
		ajaxSettingsasync(false);
	
		$(document).ready(function(){
			pageinitcart();
		});
		
		function pageinitcart(){
			var cartt=cartHelper.getCart();
			var items=cartt.items;
			$.each(items,function(index,item){
				initGood(item.id,item.goodid,item.count,item.img,item.xiangqing);
			
			});
			initallinputaddmin();
		}
		
		function initGood(id,goodid,count,img,xiangqing){
			var url="/webserver/api/v1/good/?format=json&id="+goodid;
			 
			$.getJSON(url,function(rs){
			 
				var item=rs.objects[0];
				
				var all_=(count*item.price).toFixed(2);
				$('#shopcartitemlist').append('<ul class="item-content clearfix" id="'+id+'"><li class="td td-chk"><div class="cart-checkbox "><input class="check" type="checkbox"> </div></li><li class="td td-item"><div class="item-pic"><a href="#" target="_blank" data-title="'+item.name+'" class="J_MakePoint" data-point="tbcart.8.12"> <img src="'+img+'" width="80" height="auto" class="itempic J_ItemImg"></a></div><div class="item-info"><div class="item-basic-info"><a href="#" target="_blank" title="'+item.name+'" class="item-title J_MakePoint" data-point="tbcart.8.11">'+item.name+'</a></div></div></li><li class="td td-info"><div class="item-props"><span class="sku-line">'+xiangqing+'</span><i class="theme-login am-icon-sort-desc"></i></div></li><li class="td td-price"><div class="item-price price-promo-promo"><div class="price-content"><div class="price-line"><em class="J_Price price-now" tabindex="0">'+item.price+'</em></div></div></div></li><li class="td td-amount"><div class="amount-wrapper "><div class="item-amount "><div class="sl"><input class="min am-btn" style="width:auto" name="" type="button" value="-" /><input class="text_box"  name="" type="text" value="'+count+'"	style="width: 30px; text-align:center;margin-left:4px" /> <input class="add am-btn" name=""	type="button" value="+" style="width:auto" /></div></div></div></li><li class="td td-sum"><div class="td-inner"><em tabindex="0" class="J_ItemSum number">'+all_+'</em></div></li><li class="td td-op"><div class="td-inner"><a title="移入收藏夹" class="btn-fav" style="display:none" href="#"> 移入收藏夹</a><a href="javascript:;" data-point-url="#" class="delete"> 删除</a></div></li></ul>');
				$('#'+id).find('input[type="checkbox"]').click(function(){
					refreshAll();
				
				});
				$('#'+id).find('.delete').click(function(){
				
					/* var bb=[];
 * 
 * var aa={}; aa.NAME="确认"; aa.ACTION=function(){ delAAddr(id); };
 * 
 * bb.push(aa); aa={}; aa.NAME="取消"; aa.ACTION=function(){
 *  }; bb.push(aa); toastwithactions("确认删除?",bb);*/
					var bb=[];
					var aa={};
					aa.NAME="确认";
					aa.ACTION=function(){
						 
						cartHelper.Del(id);
						$('ul#'+id).remove();
						refreshAll();
						
					};
					bb.push(aa);
					aa={};
					aa.NAME="取消";
					aa.ACTION=function(){};
					bb.push(aa);
					toastwithactions('确认删除?',bb);
				
				});
				 
				
				
			 
				/*
				$('ul li#'+id).find('.gwc-del').click(function(){
					cartHelper.Del(id) ;
					$('ul li#'+id).remove();
					refreshAll();
					
					 
				});
				
				$('ul li#'+id).find('.addOne').click(function(){
					 
					cartHelper.addOne(id) ;
					$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
					refreshAll();
					$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao_black.png")');
					 
				});
				
				$('ul li#'+id).find('.minus').click(function(){
					 
					cartHelper.DelOne(id) ;
					var aa=cartHelper.Finditem(id);
					if(aa==null){
						$('ul li#'+id).remove();
					}else{
						$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
						if(aa.count<2){
							$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao.png")');
						}
					}
					refreshAll();
					
					
					 
				});
				
				$('ul li#'+id).find('.numshow').change(function(e) {
					var cart = cartHelper.getCart();
					var index = cartHelper.Find(id);
					if (index > -1) {
						
					} else {
						alert('非法页面');	
					}
					
					var now_num=parseInt($(this).val());
					var count=0;
					if(now_num>0){
						count=now_num-cart.items[index].count;
						
					}else{
						return;
					}
					
					cart.items[index].count+=count;
					cart.count+=count;
					cart.total += parseInt(cart.items[index].price*count);
					cartHelper.Save();
					$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
					if(cart.items[index].count<2){
						$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao.png")');
					}
					 
					refreshAll();
					
                });
				*/
			
			
             
			
			});
		}
		
		
		
		function initallinputaddmin(){
			$('#shopcartitemlist').find('ul').each(function(index,item){
				var id=$(this).attr('id');
				var add=$(this).find('.add');
				var min=$(this).find('.min');
				var inp=$(this).find('.text_box');
				inp.change(function(){
					var aa=$(this).val().replace(/[^0-9]/g,'');
					if(aa==''||aa<1){
						aa=1;
					}
					$(this).val(aa);
					
					
					var cart = cartHelper.getCart();
					var index = cartHelper.Find(id);
					if (index > -1) {
						
					} else {
						alert('非法页面');	
					}
					
					var now_num=parseInt($(this).val());
					var count=0;
					if(now_num>0){
						count=now_num-cart.items[index].count;
						
					}else{
						return;
					}
					
					cart.items[index].count+=count;
					cart.count+=count;
					cart.total += parseInt(cart.items[index].price*count);
					cartHelper.Save();
					$(this).val(cartHelper.Finditem(id).count);
					 
					 
					refreshAll();
					
				});
				add.click(function(){
					var aa=parseInt(inp.val());
					 
					inp.val(aa+1);
					cartHelper.addOne(id);
					refreshAll();
					
				});
				min.click(function(){
					var aa=parseInt(inp.val());
					if(aa>1){
						inp.val(aa-1);
						cartHelper.DelOne(id);
					}
					
					
					refreshAll();
					
				
				});
				
			});
		}
		
		
		function refreshAll(){
			var carrt=cartHelper.getCart();
			
			var count = 0;
			var price=0;
			$('#shopcartitemlist ul').each(function(index,item){
				var id=$(this).attr('id');
				 
				var spitem=cartHelper.Finditem(id); 
				var aal_=spitem.count*spitem.price*0.01;
				$(this).find('.J_ItemSum').html(aal_.toFixed(2));
				if($(this).find('input[type="checkbox"]').is(':checked')){
					count+=spitem.count;
					price+=spitem.count*spitem.price;
				
				}
				
				
			});
			
			
			
			
			
			
			
			
			
			
			$('#J_SelectedItemsCount').html(count);
			$('#J_Total').html((price*0.01).toFixed(2)); 
		
		}
		
		$('#J_SelectAllCbx2').change(function(){
			if($(this).is(':checked')){
				$('#shopcartitemlist ul').find('input[type="checkbox"]').prop("checked",true);
				 
			}else{
				$('#shopcartitemlist ul').find('input[type="checkbox"]').removeAttr('checked');
				 
				
			}
			refreshAll();
			
		});
		
		$('.deleteAll').click(function(){
			 
			
			$('ul').each(function(index,item){
				var id=$(this).attr('id');
				if($(this).find('input[type="checkbox"]').is(':checked')){
					 
					var bb=[];
					var aa={};
					aa.NAME="确认";
					aa.ACTION=function(){
						 
						cartHelper.Del(id);
						$('ul#'+id).remove();
						refreshAll();
						
					};
					bb.push(aa);
					aa={};
					aa.NAME="取消";
					aa.ACTION=function(){};
					bb.push(aa);
					toastwithactions('确认删除?',bb);
				
				}
				
				
			});
		});
		
		function getOpenid(){
			var urll = '/weixin/getopenid/';
			var aa={};
			aa.code='';
			$.ajax({
				url : urll,
				data :  JSON.stringify(aa),
				async:isasync,
				contentType : "application/json;",
				dataType : "json",
				type : "POST",
				success :function(aa){
					var bb=[];
					$('#shopcartitemlist ul').each(function(index,item){
						var cart = cartHelper.getCart();
						var id = $(this).attr('id');
						if($(this).find('input[type="checkbox"]').is(':checked')){
							
							var index = cartHelper.Find(id);
							if (index > -1) {
								var aid={};
								aid.ID = ""+id;
								bb.push(aid);
							}
							
						}
					});
					if(bb.length==0){
						toast('尚未选择商品');
						return ;
					}
					savepayshangpingids(bb);
					document.location.href="pay_pc.html";
				 
					
				},
				error: function(){
					toastwithaction('尚未登录',function(){
						document.location.href="login_pc.html";
					});
					
				}
			});
		}
		
		$('#J_Go').click(function(){
			
			getOpenid();
		});
		
		 
		
		 
		
		
		
		 
		 



	</script>
</body>
</html>